<template>
	<view style="background-color: #F8F8F8;background-size: 500rpx;background-repeat: no-repeat;background-position-y: bottom;background-position-x: 170%;">
	<view style="height: auto;">
		<div class="test-component">
		  <hm-friends-list :options="list"></hm-friends-list>
		</div>
	</view>
	<scroll-view class="dialogue">
		<view class="right">
			小度小度，开空调
		</view>
		<view class="right">
			小度小度，空调调到制热
		</view>
		<view class="right">
			小度小度，温度调高2度
		</view>
		<view class="right">
			小度小度，温度调到26度
		</view>
	</scroll-view>
	</view>
</template>

<script>
import HmFriendsList from '@/components/air-list/index.vue'
import {_airOpen,_airClose,_airSetTem,_airIncTem,_airDecTem,_airSelectMode,_airSetWindSpeed} from '@/common/vmeitime-http/controller.js'
import Vue from 'vue'
export default {
  components: { HmFriendsList },
  data() {
    return {
		tepvalue:0,
		time:null,
		list:{
				friendsList: '空调控制',
				static:1,
				list:[
					
				],
			}		
    };
  },
  onShow(){
		let list = uni.getStorageSync('equipmentlist').AIR_CONDITION
		for (var i = 0; i < list.length; i++) {
			list[i].air = {
							airTemp:16  ,//空调温度
							airActive:0 ,//空调模式 制冷：0，制热：1，
							airSwitch:1  ,//0：关，1：开
							airWindy:1 ,//1:低风速，2：中风速，3：高风速
							airDehumidify:0  //0：除湿模式关，1：除湿模式开
						}
			list.name = '空调'+i+'控制'
		}
		this.list.list = list
   },
  methods:{
    btnclick(item,index) {
		let airlist = this.list.list[index].air
		var obj = {
			  "duerosType": "AIR_CONDITION",
			  "equipId": this.list.list[index].equipId,
			  "hotelId": uni.getStorageSync('controller').hotleId,
			  "position": this.list.list[index].position,
			  "positionBak": this.list.list[index].positionBak,
			  "realName":uni.getStorageSync('controller').realName,
			  "roomId": uni.getStorageSync('controller').id,
			  "roomNumber": uni.getStorageSync('controller').localId,
			  "value":0
			}
		console.log(item)
		if(!airlist.airSwitch && item != 1){
			uni.showToast({
				icon:"none",
				title:"请打开空调再操作"
			})
			return
		}
		if(item != 2 && item != 3 && item != 6 && item != 7){
			uni.showLoading({
				title:"加载中"
			})
		}
		switch(item){
			case 1:
			console.log(index)
				airlist.airSwitch = !airlist.airSwitch
				console.log(airlist.airSwitch)
				if(!airlist.airSwitch){
					_airClose(obj).then( res =>{
						console.log(res)
						uni.showToast({
							title:"关闭空调"
						})
					})
				}else{
					_airOpen(obj).then( res =>{
						console.log(res)
						uni.showToast({
							title:"打开空调"
						})
					})
				}
				break;
			case 2:
				clearTimeout(this.time);
				 if(airlist.airWindy<3){
					airlist.airWindy++;
				 }else{
					airlist.airWindy = 3
				 }
				 
				this.time = setTimeout(()=>{
					uni.showLoading({
						title:"加载中"
					})
					obj.value = airlist.airWindy;
					_airSetWindSpeed(obj).then(res =>{
						console.log(res)
						uni.showToast({
						  title: '风速设置成功',
						})
					})
					
				}, 500);
				
				break;
			case 3:
				clearTimeout(this.time);
				if(airlist.airWindy>1){
				 	airlist.airWindy--;
				 }else{
				 	airlist.airWindy = 1
				 }
				 
				this.time = setTimeout(()=>{
					uni.showLoading({
						title:"加载中"
					})
					obj.value = airlist.airWindy;
					_airSetWindSpeed(obj).then(res =>{
						console.log(res)
						uni.showToast({
						  title: '风速设置成功',
						})
					})
					
				}, 500);
				break;
			case 4:
				obj.value = 0;
				_airSelectMode(obj).then( res =>{
					console.log(res)
					airlist.airActive = 0;
					uni.showToast({
					  title: '制冷模式',
					})
				})
				break;
			case 5:
				obj.value = 1;
				_airSelectMode(obj).then( res =>{
					console.log(res)
					airlist.airActive = 1;
					uni.showToast({
					  title: '制热模式',
					})
				})
				break;
			case 6:
				clearTimeout(this.time);
				 if(airlist.airTemp<32){
				 	this.tepvalue++
				 	airlist.airTemp++
				 }else{
				 	airlist.airTemp = 32
					this.$api.msg('最高温度32℃')
					return false;
				 }
				 
				this.time = setTimeout(()=>{
					uni.showLoading({
						title:"加载中"
					})
					obj.value = this.tepvalue;
					_airIncTem(obj).then(res =>{
						console.log(JSON.parse(res.data.data),5555)
						this.tepvalue = 0
						airlist.airTemp = JSON.parse(res.data.data).payload.temperature.value
						uni.showToast({
						  title: '温度设置成功',
						})
					})
					
				}, 500);
				break;
			case 7:
				clearTimeout(this.time);
				 console.log(airlist.airTemp,this.tepvalue)
				if(airlist.airTemp>16){
					this.tepvalue++
					airlist.airTemp--
				}else{
					airlist.airTemp = 16;
					this.$api.msg('最低温度16℃')
					return false;
				}
				
				this.time = setTimeout(()=>{
					uni.showLoading({
						title:"加载中"
					})
					obj.value = this.tepvalue;
					_airDecTem(obj).then(res =>{
						console.log(JSON.parse(res.data.data))
						airlist.airTemp = JSON.parse(res.data.data).payload.temperature.value
						this.tepvalue = 0
						uni.showToast({
						  title: '温度设置成功',
						})
					})
					
				}, 500);
				break;
			default:
				uni.showToast({
					icon:"none",
					title:"您的空调暂不支持此操作"
				})
				break;
		}
		this.$set(this.list.list[index],airlist)
		// 	 if(this.list.list[item].active==1){
		// 		 this.list.list[item].active=0
		// 	//	Vue.set(item,'active', '0')
				
		// 	}else{
		// 		this.list.list[item].active=1
		// //	Vue.set(item,'active','1')
		// 	// 	item.active = 1
		// 	}
		// 	//console.log(item)
	
    }
  }
};
</script>


<style>
	page{
		height: 100%;
		/* background-color: rgba(1,1,1,0.5); */
		background-color: #F8F8F8;
		/* background: linear-gradient(to top, #22223c, #3f3f63); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+  */
	}
	
	.dialogue{
		margin-top: 60rpx;
		/* padding-left: 20rpx; */
		font-size: 30rpx;
		color: #ffffff;
		display: flex;
		flex-direction: column;
		


	}
	.dialogue .right{
		height: 80rpx;
		padding: 0 25rpx 0 25rpx;
		border-radius: 25rpx;
		border-top-left-radius: 0rpx;
		/* background-color: rgb(121,125,210,0.4);*/
		 background-color: #FFBC15;
		display: flex;
		align-items: center;
		margin-bottom: 22px;
		width: fit-content;
		box-shadow: 0px 1px 10px rgba(111, 113, 118, 0.5);
		margin-left: 20rpx;

	}
</style>